//
//  BaseModel.m
//  UI22_项目框架
//
//  Created by dllo on 15/7/3.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel
#pragma mark - dealloc
- (void)dealloc
{
    [super dealloc];
}
#pragma mark - 初始化
- (instancetype)initWithDic:(NSDictionary *)dic
{
    if ([super init]) {
        //KVC赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
#pragma mark - 便利构造器
+(instancetype)baseModelWithDic:(NSDictionary *)dic
{
    id object = [[[[self class] alloc] initWithDic:dic] autorelease];
    return object;
}
#pragma mark - 转化方法
+ (NSMutableArray *)arrayWithModelByArray:(NSArray *)array
{
    //创建一个可变数组 保存Model 并作为返回值
    NSMutableArray *arr = [NSMutableArray array];
    //遍历 参数数组
    for (NSDictionary * dic in array) {
        @autoreleasepool {
            //创建对象
            id model = [[self class] baseModelWithDic:dic];
            [arr addObject:model];
        }
    }
    return arr;
}
#pragma mark - 容错方法()
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}
-(id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

@end
